﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using JCTimes.DomainModel.Views;
using JCTimes.DomainModel.Entity;
using JCTimes.EFRepository.Specification;
using JCTimes.Portal.Infrastructure;
using System.Data.SqlClient;
using JCTimes.Portal.Models;

namespace JCTimes.Portal.Specification
{
    public class PDAUsersFunctionsSpecification
    {
        public static Expression<Func<V_PDAUsersFunctions, bool>> Get_V_PDAUsersFunctions_Pred(Searcher searcher)
        {
            Specification<V_PDAUsersFunctions> spec = new TrueSpecification<V_PDAUsersFunctions>();
            UserInfo uinfo = SessionHelper.CurrUser;
            if (uinfo.RoleID == Constant.Agency)
            {
                spec &= new DirectSpecification<V_PDAUsersFunctions>(x =>x.ParentID==uinfo.UserID);
            }
            foreach (var key in searcher.Keys)
            {
                switch (key)
                {
                    case "createusersid":
                        string createuserid = searcher[key].Trim();
                        spec &= new DirectSpecification<V_PDAUsersFunctions>(x => x.ParentID != null && x.ParentID == createuserid);
                        break;
                    case "usersid":
                        string usersid = searcher[key];
                        spec &= new DirectSpecification<V_PDAUsersFunctions>(x => x.UsersID != null && x.UsersID == usersid);
                        break;
                    default:
                        break;
                }
            }

            return spec.SatisfiedBy();
        }
    }
}